package dimension.starry.event;

import dimension.starry.Tasks.PlayerTaskManager;
import dimension.starry.Tasks.TaskManager;
import dimension.starry.item.FoodRot;
import dimension.starry.entity.MonsterLevel;
import dimension.starry.effect.EffectResult;
import dimension.starry.gui.Bar.HealthBar;
import dimension.starry.gui.Bar.Hud;
import dimension.starry.gui.Bar.UID;
import dimension.starry.gui.ShowItemDescription;
import dimension.starry.player.ComputedPlayerInfo;
import dimension.starry.player.LevelUpper;
import dimension.starry.player.MagicRecover;
import dimension.starry.player.WaterDecrease;
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.fabric.api.entity.event.v1.ServerEntityCombatEvents;
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;

public class EventListener {

  public static void onInitialize() {
    ServerEntityCombatEvents.AFTER_KILLED_OTHER_ENTITY.register(LevelUpper::onKilling);
    ServerPlayerEvents.AFTER_RESPAWN.register(LevelUpper::onPlayerRespawn);
    ServerPlayerEvents.AFTER_RESPAWN.register(MagicRecover::onPlayerRespawn);
    ServerPlayerEvents.AFTER_RESPAWN.register(WaterDecrease::onPlayerRespawn);
    ServerLifecycleEvents.SERVER_STARTED.register(PlayerTaskManager::onServerStarted);
    ServerLifecycleEvents.SERVER_STARTED.register(TaskManager::onServerStarted);
    ServerTickEvents.START_SERVER_TICK.register(TaskManager::onStartTick);
    Events.LIVING_DAMAGE_CALC_EVENT.register(ComputedPlayerInfo::changeDamage);
    Events.PLAYER_OPEN_CONTAINER_EVENT.register(FoodRot::onPlayerOpenContainer);
    Events.PLAYER_PICKUP_ITEM_EVENT.register(FoodRot::onPlayerPickupItem);
    Events.PLAYER_FINISH_USING_ITEM_EVENT.register(EffectResult::onPlayerFinishUsingItem);
    ServerEntityEvents.ENTITY_LOAD.register(MonsterLevel::onLoad);
    ServerEntityEvents.EQUIPMENT_CHANGE.register(LevelUpper::onPlayerEquipmentChange);
  }

  public static void onInitializeClient() {
    HudRenderCallback.EVENT.register(HealthBar::onHudRender);
    Events.HUD_RENDER_EVENT.register(Hud::onHudRender);
    HudRenderCallback.EVENT.register(UID::onHudRender);
    ItemTooltipCallback.EVENT.register(ShowItemDescription::onItemTooltip);
  }

}
